<%--
 *  File:   Regionalcoveragereports.jsp
 *  Desc:	Report Director depend on eSpreadsheet
 *
 *  Date		         Author		      Changes
 *  2009-12-15	  		visazhou	 	  Created
 *   
 *
 *  Copyright (C) 2000 - 2008 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<%//init param
			String privilegeCode = "10224";
			//String strTableName = "";
			String strModuleName = "COM";
			String contextPath = request.getContextPath();

			%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<%@ include file="/rpt/ReportURL.inc"%>
<iframe name="reloadHandler" style="display:none"></iframe>
<html>
<head>
<title>Regionalcoveragereports</title>
<PageFlow:CheckPageFlow pageName="p_employeeinfo" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>


<%@ include file="/inc/SummaryDivision.inc" %>
<%Vector totalsummary = (Vector) pageContext.getAttribute("totalsummary");
			if (totalsummary == null)
				totalsummary = new Vector();		

			HashMap deptinfo = (HashMap) session.getAttribute("deptinfo");
			if (deptinfo == null)
				deptinfo = new HashMap();
			
			HashMap UserInfo = (HashMap) session.getAttribute("userinfo");
			if (UserInfo == null)
				UserInfo = new HashMap();
    Integer loginemployeeid = (Integer)UserInfo.get("employeeid");
    
    java.util.Calendar cal = java.util.Calendar.getInstance(); 
    String flag = (String)pageContext.getAttribute("flag");
    
    HashMap orgInfo = (HashMap)pageContext.getAttribute("orginfo");

    if(orgInfo == null)
      orgInfo = new HashMap();
    
    Integer ishead = (Integer)orgInfo.get("ischain");
    if(ishead==null)
  	  ishead = new Integer(-1);
			%>

<%--  put your custom script here   --%>

<script language="JavaScript">

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  	editform.action = "Regionalcoveragereports.jsp?<%= OvalTools.randomURL() %>";
    editform.target = "_self";
    isRunning = true;
    editform.submit();
}



function downloadcsv() {
	var begindate = document.cform.beginyear.value+"-"+document.cform.beginmonth.value;
	//var beginmonth = document.cform.beginmonth.value;
	var enddate = document.cform.endyear.value+"-"+document.cform.endmonth.value;
	//var endmonth = document.cform.endmonth.value;
	var prodid = document.cform.prodid.value;
	var orgid = document.cform.orgid.value;
	var partnerid = document.cform.partnerid.value;
	var areaid = document.cform.areaid.value;
	var salestype = document.cform.salestype.value;
	var regionareaid = document.cform.regionareaid.value;
	var salesdetailtype = document.cform.salesdetailtype.value;

    var viewflowdatetype = document.cform.viewflowdatetype.value;


    if (salesdetailtype == 1)
	{     if (viewflowdatetype == 1)
	        {       
                   var url1 = "<%=reportURL%>/csv?__report=/ovalreport/salesdetail.txt"+"&salesbegindate="+begindate  +"&salesenddate="+enddate+"&loginenddate="+enddate +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
    
                      var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                       popwindow = window.open(url1, "n1window", strstatus);
                        
                        
                                    }else
            {
                var url1 = "<%=reportURL%>/csv?__report=/ovalreport/salesdetail.txt"+"&begindate="+begindate  +"&enddate="+enddate +"&loginenddate="+enddate +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
                        var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                        popwindow = window.open(url1, "n1window", strstatus);
            }
    }else{
	if (salesdetailtype == 2)
	{
        if (viewflowdatetype == 1)
	        {
                 var url1 = "<%=reportURL%>/csv?__report=/ovalreport/Purchasedetail.txt"+"&salesbegindate="+begindate  +"&salesenddate="+enddate +"&loginenddate="+enddate +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
                var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                popwindow = window.open(url1, "n1window", strstatus);
            }else
            {
                var url1 = "<%=reportURL%>/csv?__report=/ovalreport/Purchasedetail.txt"+"&begindate="+begindate  +"&enddate="+enddate+"&loginenddate="+enddate  +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
                    var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                    popwindow = window.open(url1, "n1window", strstatus);
            }

	}
	else
	{
        if (viewflowdatetype == 1)
	        {
                 var url1 = "<%=reportURL%>/csv?__report=/ovalreport/Alldetail.txt"+"&salesbegindate="+begindate  +"&salesenddate="+enddate +"&loginenddate="+enddate +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
                    var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                    popwindow = window.open(url1, "n1window", strstatus);
            }else
            {
               var url1 = "<%=reportURL%>/csv?__report=/ovalreport/Alldetail.txt"+"&begindate="+begindate  +"&enddate="+enddate +"&loginenddate="+enddate +"&itemidstr=" +prodid +"&prodids=" +prodid +"&orgidstr="+orgid+"&partneridstr="+partnerid+"&areaidstr="+areaid+"&salestype="+salestype+"&partnerareaidstr="+regionareaid+"&loginuserid=<%=loginemployeeid%>&zip=true";
                var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
                popwindow = window.open(url1, "n1window", strstatus);
            }

	}
    }
}

function page_popBusinessarea()
{
  if (typeof popwindow != 'undefined') popwindow.close();
  popwindow = window.open("<%=contextPath%>/masterdata/ogm/zylstdbusinessareapop.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>","newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
}

function page_popProductbrand()
{
  if (typeof popwindow != 'undefined') popwindow.close();
  popwindow = window.open("<%=contextPath%>/masterdata/upm/ProductbrandPopWindow.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>","newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
}
function popRep() {
	//var regionid=cform.regionid.value;
	//var proviceofficecode = document.cform.proviceofficelist.value;
	//var businessareacode = document.cform.businessarealist.value;
	var regioncode=document.cform.regioncode.value;
	var status = "height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
	var url = "<%=contextPath%>/masterdata/ogm/zylstdbusinessareapop.jsp?<%= OvalTools.randomURL() %>&regioncode="+regioncode;
	
	popwindow = window.open(url, "newwindow", status);
  }


function setContact(id,type,name){

	document.cform.regionareaid.value=id;
	document.cform.regionname.value=name;
}

function set_orgNameByPopWindow(productgroupid,productgroupcode,productgroupname){

	document.cform.productbrandid.value=productgroupid;
	document.cform.productbrandname.value=productgroupname;
}
var popwindow;

function page_setRegion(code,name)
{
  if(code != document.cform.regioncode.value)
  {
    //document.cform.citycode.value = " ";
    //document.cform.cityname.value = " ";
    //document.cform.countycode.value = " ";
    //document.cform.countyname.value = " ";
  }
  document.cform.regioncode.value= code;
  document.cform.regionname.value = name;
  if (popwindow != null)
    popwindow.close();
}

function page_selectProvince()
{
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/zylstdbusinessareapop.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}


function exportCSV(){
	var date = document.cform.startyears.value+"-"+document.cform.startmonths.value;

	//cform.deptid.options[0].selected=true;
	/**
	deptid 		   	部门Id
	regionareaid 	省区Id
	areatype     	业务区域类型
	productbrandid  产品组
	
	*/
	var deptid = document.cform.deptids.value;
	var regionareaid = document.cform.regionareaid.value;
	var areatype = document.cform.areatype.value;
	var productbrandid = document.cform.productbrandid.value;
	//alert(date);
	//alert(deptid);
	//alert(regionareaid);
	//alert(areatype);
	//alert(productbrandid);
	
    if(deptid ==-1) deptid="";if(areatype==-1) areatype="";
	//if( !document.cform.deptids.options[0].selected || !document.cform.areatype.options[0].selected)
	    var url = "<%=reportURL%>/servlet/ExcecuteReport/AreaInfo.sox?__format=xlsx&__folder=/ovalreport&deptid="+deptid+"&areatype="+areatype+"&date="+date+"&regionareaid="+regionareaid+"&productbrandid="+productbrandid;
	    var strstatus="height=768, width=1024,top=0,left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
	   
	    popwindow = window.open(url, "n1window", strstatus);
}
</script>

</head>
<body style="overflow: auto;" >
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
	<input type="hidden" name="pagename" value="p_employeeinfo">
	<input type="hidden" name="actionname">
	<input type="hidden" name="prodcode">
    <input type="hidden" name="flag"/>
	<custom:hidden property="languagecode" scope="session" name="userinfo"/>
	<custom:hidden property="contactid" scope="session" name="userinfo" changedName="loginid"/>
	<%--  page location   --%>
<%@ include file="/inc/PageLocation.inc"%>


<table width="100%" border="0" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
<!-------------------------------------1 row -------------------------------------------------->
	<tr>
				<%
                  String year = cal.get(Calendar.YEAR)+"";     
					String month = cal.get(Calendar.MONTH)+"";
					if(cal.get(Calendar.MONTH) == 0){
						month = "12";
						year = (cal.get(Calendar.YEAR)-1)+"";
					}  
					
				%>
	
		<td class="title_center">
			<div align="right">		
				<%=label.getLabelName("L_Year1")+label.getLabelName("L_Colon")%>
				
			</div>
		</td>
		
		<td>
			<custom:selectdic property="startyears" dictType="Years" command="notnull" value="<%=year %>" label="L_Year1" />
		</td>
		<td class="title_center">
			<div align="right">		
					<%=label.getLabelName("L_Month")+label.getLabelName("L_Colon")%>
			</div>
		</td>
		<td>
			<custom:selectdic property="startmonths" dictType="Months" command="notnull" value="<%=month %>" label="L_Month" />
		</td>		
				
				
		<td class="title_center">
			<div align="right">
				<%=label.getLabelName("L_Department")+ label.getLabelName("L_Colon")%>
			</div>
		</td>
		<td>
			       <custom:select property="deptids" optionsName="alldeptnames"
							optionValueKey="deptid" optionInnerTextKey="deptname" defaultValue="--------"/>
	   </td>
	
		<td class="title_center">
			<div align="right">
				<%=label.getLabelName("L_AreaType")+label.getLabelName("L_Colon")%>
			</div>
		</td>
		<td>
			
			<custom:selectdic dictType="ZYLAreaType" property="areatype"  defaultValue="------" defaultValueCost=""/>
			
		</td>

	</tr>


<!-------------------------------------2 row -------------------------------------------------->
	<tr>
		 <td class="title_center">
			<div align="right">
				<%=label.getLabelName("L_Provicetdr")+label.getLabelName("L_Colon")%>
			</div>
		</td>
		<td>
					<custom:text property="regionname" 
					size="20" readonly="false" style="border:1px #7F9DB9 solid;" /> <a
					onClick="javascript:page_popBusinessarea();"><custom:button type="3"
					label="L_Asterisk" imgsrc="flash.gif" border="0" /></a><custom:hidden property="regionareaid" /></td>
	
	

		<td class="title_center">
			<div align="right">
				<%=label.getLabelName("L_ProductGroupName")+label.getLabelName("L_Colon")%>
			</div>
		</td>
		<td>
				<custom:hidden property="productbrandid" />
		           	<custom:text property="productbrandname"/>
		           	<!--<custom:hidden property="orgid"/>-->
		           	<a onclick="page_popProductbrand();"><custom:button type="3" value="*"/></a>
		</td>
	</tr>

<!--	-----------------------------------------4row---------------------------------------->

 </table>

		 <table width="100%" cellspacing="0" cellpadding="0">
		        <tr>
		          <td class="summary_top"></td>
		        </tr>
		        
		        <tr>
		          	<td class="td_center">
			  		
				  		
				  		<a onclick="javascript:exportCSV();"><input name="button" type="button" value="<%=label.getLabelName("L_ExportCSV")%>" /></a>

					</td>
		        </tr>
     	</table>
	</table>
</form>
</body>
</html>
